package com.lishe.lishe.lishe.module.shopingcart.presenter;

import com.lishe.lishe.lishe.bean.AddressBean;
import com.lishe.lishe.lishe.common.Globals;
import com.lishe.lishe.lishe.module.mall.bean.GoodsMallResponse;
import com.lishe.lishe.lishe.module.mall.bean.HomeResponse;
import com.lishe.lishe.lishe.module.shopingcart.bean.ShopCarBean;
import com.lishe.lishe.lishe.module.shopingcart.bean.SubmitOrderBean;
import com.lishe.lishe.lishe.utils.LogUtil;
import com.lishe.lishe.net.BaseHttpLoader;
import com.lishe.lishe.net.BaseProtocal;
import com.lishe.lishe.net.NetAPI;
import com.lishe.lishe.net.ResultListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

/**
 * Bin
 */

public class ShopCarModule {

    public void getShopCarData(ResultListener listener) {
        BaseHttpLoader http = new BaseHttpLoader(ShopCarBean.class, Globals.LISHE_URL) {
            @Override
            public Observable<ResponseBody> structureObservable(NetAPI api) {
                return api.cartList(Globals.getToken());
            }
        };
        http.executor(listener);
    }

    public void getAddressData(ResultListener listener) {
        BaseHttpLoader http = new BaseHttpLoader(AddressBean.class, Globals.LISHE_URL) {
            @Override
            public Observable<ResponseBody> structureObservable(NetAPI api) {
                return api.getAddress(Globals.getToken());
            }
        };
        http.executor(listener);
    }

    public void submitOrder(ResultListener listener, ArrayList<String> cartIds) {
        BaseHttpLoader http = new BaseHttpLoader(SubmitOrderBean.class, Globals.LISHE_URL) {
            @Override
            public Observable<ResponseBody> structureObservable(NetAPI api) {
                return api.submitOrder(Globals.getToken(), cartIds);
            }
        };
        http.executor(listener);
    }

    public void modifyDefAddr(ResultListener listener, String addrId) {
        BaseHttpLoader http = new BaseHttpLoader(BaseProtocal.class, Globals.LISHE_URL) {
            @Override
            public Observable<ResponseBody> structureObservable(NetAPI api) {
                return api.modifyDefAddr(Globals.getToken(), addrId);
            }
        };
        http.executor(listener);
    }

}
